<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" isELIgnored="false"%>
<%@ include file="/WEB-INF/views/shared/taglib.jsp"%>
<%
	request.setAttribute("title", "转入余额");
%>
<%@ include file="/WEB-INF/views/shared/master/weContentHeader.jsp"%>
<style>
body{
	background-color: #f5f5f5;
}
.weui-cells {
	margin-top: 0px;
}
.weui-cell {
	background-color: white;
	color: #333333;
	padding: 15px;
}
.withdrawmoney>p {
	padding: 15px 10px;
	color: black;
	font-size: 16px;
}

.money {
	margin: 0px 10px;
	color: red;
}

#exchangeMoney {
	color: red;
}

.color-blue {
	color: #2196F3;
}

.bottom-btn {
	margin: 15px;
	padding: 2px;
	background-color: #2196F3;
}

.weui-btn_primary:not (.weui-btn_disabled ):active {
	background-color: #2196F3;
}

.weui-btn_disabled {
	background-color: #79c0f9 !important;
	color:
}

.weui-cell:before {
	border-top: 0px;
}

.share {
	border-bottom: 0px;
}

.service-award {
	border-top: 2px solid #eee;
}

#shareLevel {
	display: none;
}

.share-award {
	border-bottom: 0px;
}

.weui-cell_define {
	-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
	color: inherit
}

.weui-cell_define:active {
	background-color: #ececec
}

.weui-cell_define .weui-cell__ft {
	padding-right: 13px;
	position: relative
}

.weui-cell_define .weui-cell__ft:after {
	content: " ";
	display: inline-block;
	height: 6px;
	width: 6px;
	border-width: 0 2px 2px 0;
	border-color: #c8c8cd;
	border-style: solid;
	-webkit-transform: matrix(.71, .71, -.71, .71, 0, 0);
	transform: matrix(.71, .71, -.71, .71, 0, 0);
	position: relative;
	top: -2px;
	position: absolute;
	top: 50%;
	margin-top: -4px;
	right: 2px
}
	#money::-webkit-input-placeholder{
		color: #999;
	}
</style>

<%@ include file="/WEB-INF/views/shared/master/weTitle.jsp"%>

<div class="goback" data-back-href="<c:url value='/wechat/acc/myWealth/aboutGoldbean'/>"></div><div class="withdrawmoney">
	
<div style="background-color: #f5f5f5;padding: 1.3rem 15px">
	<p>
		<span style="color: #666666;">金豆：</span>
		<span style="color: #1fa0db;font-size: 1.5rem">
			<fmt:formatNumber value="${allgolden}" pattern="#" minFractionDigits="0" > </fmt:formatNumber>	
		</span>
	</p>
</div>

<div class="weui-cell">
	<div class="weui-cell__bd">
		<p>转出</p>
	</div>
</div>
<div class="weui-cell"  style="border-bottom: 1px solid #eee;border-bottom-left-radius: 0.2rem;border-bottom-right-radius: 0.2rem;padding-top: 0.2rem">
	<div class="weui-cell__hd">
		&nbsp;
	</div>
	<div class="weui-cell__bd">
		<input class="weui-input" id="money" type="number" placeholder="请输入100的整数" style="font-size: 18px;" onkeyup="btnColor(),checkMoney()"/>
	</div>
	<div class="weui-cell__ft">
		100金豆=1元
	</div>
</div>
<span class="info" style="color: #ea693f; margin-left: 20px" hidden></span>
<div class="weui-cell">
	<div class="weui-cell__bd">
		<p>可用金豆：
		<fmt:formatNumber type="number" value="${usegolden}"  pattern="#" minFractionDigits="0" />
		个</p>
	</div>
	<div class="weui-cell__ft" style="color: #1fa0db" onclick="withdrawals()" >
		 全部转余额
	</div>
</div>
<div style="width: 100%; height: 10px; background-color: #f5f5f5;"></div>
<div class="weui-cell"style="border-bottom: 2px solid #eee;font-size: 18px">
	<div class="weui-cell__hd"></div>
	<div class="weui-cell__bd">
		<p>
			<span>不可用金豆：</span> 
				<fmt:formatNumber type="number" value="${uselessgolden}" pattern="#" minFractionDigits="0" />
			<span>个</span>
		</p>
	</div>
	<div class="weui-cell__ft" style="color: #1fa0db">详情</div>
</div>	
<div style="z-index: 500;">
	<a href="javascript:withdraw();"data-href="<c:url value='/wechat/acc/myWealth/myWealth'/>"class="weui-btn weui-btn_primary bottom-btn withdraw weui-btn_disabled"id="btn">转&nbsp;&nbsp;&nbsp;&nbsp;入</a>
</div>
	
<%@ include file="/WEB-INF/views/shared/scripts/jquery.jsp"%>
<%@ include file="/WEB-INF/views/shared/scripts/jqweui.jsp"%>
<%@ include file="/WEB-INF/views/shared/master/weContentFooter.jsp"%>
<%@ include file="/WEB-INF/views/shared/scripts/tabmob.jsp"%>

<script type="text/javascript">
	$(function() {
		/* 点击显示不可用详情*/
		$("#share-father").on("click", function() {
			if ($(this).attr("class").indexOf("weui-cell_access") > 0) {
				$(this).removeClass("weui-cell_access");
				$(this).addClass("weui-cell_define");
			} else {
				$(this).removeClass("weui-cell_define");
				$(this).addClass("weui-cell_access");
			}

			$("#shareLevel").toggle(300);
		});
	});
	
	//点击转入按钮要执行的操作 
	function withdraw() {
		if (!checkInput()) {
			return;
		}
		
		var money = $("#money").val();
		
		var action = $.getVirtualPath()+"/wechat/acc/myWealth/doGoldbeanToBalance?money="+money;
		var result = $.getTextPost(action);
		if (result == "true") {
			$.toast("成功转入余额");
			setTimeout(function() {
				window.location.href = $.getVirtualPath()+"/wechat/acc/myWealth/myWealth";
			}, 500);
		} else {
			$.toast("转入余额失败", "forbidden");
		}
	}
	
	function btnColor() {
		var $withdraw = $(".withdraw");
		var $money = $("#money");
		var value = $money.val();
		if (value != '') {
			$("#btn").attr("disabled", false); 
			if ($withdraw.attr("class").indexOf("weui-btn_disabled") > 0) {
				$withdraw.removeClass("weui-btn_disabled");	
			}
		}
		if (value == ''|| value ==0) {
			$("#btn").attr("disabled", true); 
			$withdraw.addClass("weui-btn_disabled");			
		}
	}
	
	/* 检查输入 */
	function checkInput() {
		if (checkMoney()) {
			return true;
		}
		return false;
	}
	/* 检查是否输入金额 */
	function checkMoney() {
		var money = $("#money").val();
		
		var reg = /^[1-9]{1}[0-9]{0,6}[0]{2}$/;
		if (money == '') {
			$("#btn").attr("disabled", false);
			$(".info").hide();
			$("#exchangeMoney").html(0);
			return false;
		}
		else if(!reg.test(money)){
			$(".info").html("请输入100的倍数,如100,200,300...");
			$(".info").show();
			var $withdraw = $(".withdraw");
			$withdraw.addClass("weui-btn_disabled");
			
			/* $.toptip("请输入正确的金额","error"); */
			return false;
		}
		
		var allmoney ="${usegolden}" ;/*${accountInfo.goldenBean} */
		if(parseFloat(money)>parseFloat(allmoney)){
			$(".info").html("转入金豆超出可用金豆");
			$(".info").show();
			var $withdraw = $(".withdraw");
			$withdraw.addClass("weui-btn_disabled");
			return false;
		}
		$(".info").hide();
		exchangeMoney(money);
		return true;
	}
	
	//全部提现的实现
	function withdrawals(){		
		var allmoney ="${usegolden}";/* ${accountInfo.goldenBean} */
		$("#money").val(parseInt(allmoney));
		checkMoney();
		btnColor();
		
	} 
	var exchangeRate ="${exchangeRate}";
	//金豆对应金额
	function exchangeMoney(money){
		money = money/exchangeRate;
		$("#exchangeMoney").html(money);
		
	}
</script>
